package com.hutao.chargingpile.pitfall.controller;

import com.hanhan.common.exception.Assert;
import com.hanhan.common.result.ResponseEnum;
import com.hutao.chargingpile.pitfall.pojo.entity.CpHidden;
import com.hutao.chargingpile.pitfall.pojo.entity.CpSolvePerson;
import com.hutao.chargingpile.pitfall.result.R;
import com.hutao.chargingpile.pitfall.service.CpHiddenService;
import com.hutao.chargingpile.pitfall.service.CpSolvePersonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;

/**
 * <p>
 * 隐患管理表 前端控制器
 * </p>
 *
 * @author HuTao
 * @since 2023-03-23
 */
@Slf4j
@Api(tags = "隐患管理")
@RestController
@RequestMapping("/cpHiddenInfo")
//@CrossOrigin
public class CpHiddenController {

    @Resource
    private CpHiddenService cpHiddenService;

    @Resource
    private CpSolvePersonService cpSolvePersonService;
    //全查隐患信息加分页加模糊查询加时间区间查询
    @ApiOperation("查询隐患管理的信息")
    @RequestMapping("/listPage/{page}/{limit}/{createTime}/{updateTime}/{addressSite}")
    public R listPage(
            @PathVariable Integer page, @PathVariable Integer limit,
            @PathVariable String addressSite,
            @PathVariable String createTime,
            @PathVariable String updateTime){
        Map<String, Object> map = new HashMap<>();
        //开始页
        //page -= 1;
        map.put("start",(page -1) * limit);
        map.put("pagesize", limit);
        map.put("addressSite", addressSite);
        map.put("createTime", createTime);
        map.put("updateTime", updateTime);
        int count = cpHiddenService.coutHidden(map);
        return R.ok().datas("list",cpHiddenService.findAllPageHidden(map),count);
    }
    //站点信息
    @RequestMapping("/findChargingStations")
    public R findChargingStations(){
        return R.ok().data("options",cpHiddenService.findChargingStations());
    }
    //处理状态
    @RequestMapping("/findCpHandleCode")
    public R findCpHandleCode(){
        return R.ok().data("code",cpHiddenService.findCpHandleCode());
    }
    //删除隐患信息
    @ApiOperation(value = "根据id删除数据记录",notes = "逻辑删除记录")
    @DeleteMapping("/remove/{id}")
    public R removeById(
            @PathVariable Long id){
        boolean result = cpHiddenService.removeById(id);
        if (result){
            return R.ok().message("删除成功");
        }else {
            return R.error().message("删除失败");
        }
    }
    //新增隐患信息
    @RequestMapping("/save/{cphidden}")
    public R save(@RequestBody CpHidden cpHidden){
        Assert.notNull(cpHidden, ResponseEnum.BAD_SQL_GRAMMAR_ERROR);
        boolean result = cpHiddenService.dealSave(cpHidden);
        if (result){
            return R.ok().message("ok");
        }else {
            return R.error().message("no");
        }
    }
    //处理人
    @RequestMapping("/solvePerson")
    public R solvePerson(){
        List<CpSolvePerson> list = cpSolvePersonService.list();
        return R.ok().data("list",list).message("列表获取成功");
    }
    //充电桩编号类型等数据回显
    @RequestMapping("/getCpHidden")
    public R cpHidden(){
        return R.ok().data("list",cpHiddenService.list());
    }
    //隐患级别
    @RequestMapping("/getHandleType")
    public R getHandleType(){
        return R.ok().data("typeList",cpHiddenService.getHandleType());
    }
    //隐患优先级
    @RequestMapping("/getRank")
    public R getRank(){
        return R.ok().data("typeList",cpHiddenService.getRank());
    }

}

